
/*
 * 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package PCR;

import Enums.ProjectType;
import java.beans.PropertyVetoException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author marwa
 */
public class NewPCR extends javax.swing.JInternalFrame {

    /**
     * Creates new form NewPCR
     */
    String ImageTitle;
    String sampleNumber;
    String markerType;
    WorkArea obj;
    Toolbox toolbox;
    int hight;
    int width;

    public NewPCR() {
        initComponents();
        MainFrame frm = (MainFrame) java.awt.Window.getWindows()[0];
        hight = (frm.getHeight() / 2) - (this.getHeight());
        width = frm.getWidth() / 2 - (this.getWidth() / 2);

        this.setLocation(width, hight);
        obj = new WorkArea(ImageTitle, true, "PCR");
        this.getRootPane().setDefaultButton(createButton);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        Background = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        TitleTextField = new javax.swing.JTextField();
        SampleComboBox = new javax.swing.JComboBox();
        createButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        setClosable(true);
        setTitle("New PCR");

        jLabel1.setText("Title:");

        jLabel2.setText("Sample:");

        TitleTextField.setText("Untitled");

        SampleComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "4 Samples", "8 Samples", "16 Samples" }));

        createButton.setText("Create");
        createButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout BackgroundLayout = new javax.swing.GroupLayout(Background);
        Background.setLayout(BackgroundLayout);
        BackgroundLayout.setHorizontalGroup(
            BackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(BackgroundLayout.createSequentialGroup()
                .addGap(73, 73, 73)
                .addComponent(createButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
                .addComponent(cancelButton)
                .addGap(90, 90, 90))
            .addGroup(BackgroundLayout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addGroup(BackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2))
                .addGap(8, 8, 8)
                .addGroup(BackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(TitleTextField)
                    .addComponent(SampleComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 210, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        BackgroundLayout.setVerticalGroup(
            BackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(BackgroundLayout.createSequentialGroup()
                .addGap(45, 45, 45)
                .addGroup(BackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(TitleTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(21, 21, 21)
                .addGroup(BackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(SampleComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addGroup(BackgroundLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(createButton)
                    .addComponent(cancelButton))
                .addGap(41, 41, 41))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Background, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(Background, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void createButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createButtonActionPerformed
        ImageTitle = CheckTitle(TitleTextField.getText());
        sampleNumber = (String) SampleComboBox.getSelectedItem();


        MainFrame test = (MainFrame) this.getParent().getParent().getParent().getParent().getParent();
        obj.setTitle(ImageTitle);
        obj.setMarkerPos(obj.getMarkerPos());

        obj.setMarkerType(50, Integer.parseInt(sampleNumber.split(" ")[0]));
        obj.wheelBandsDrawer(Integer.parseInt(sampleNumber.split(" ")[0]));
        obj.setVisible(true);
        obj.setSize(800, 600);
        obj.setLocation(220, 10);
        obj.setProjectType(ProjectType.PCR);
        obj.toFront();
        obj.getBandsPanel().setSampleType(sampleNumber);
        obj.grabFocus();
        test.setSelectedWorkArea(obj);
        super.getDesktopPane().add(obj);
        try {
            obj.setSelected(true);
        } catch (PropertyVetoException ex) {
            Logger.getLogger(NewPCR.class.getName()).log(Level.SEVERE, null, ex);
        }
        this.setVisible(false);

        toolbox = test.getToolbox();

        test.getPositioningToolbar().setVisible(true);
    }//GEN-LAST:event_createButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel Background;
    private javax.swing.JComboBox SampleComboBox;
    private javax.swing.JTextField TitleTextField;
    private javax.swing.JButton cancelButton;
    private javax.swing.JButton createButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables

    private String CheckTitle(String text) {
        if (text.equals("Untitled") || text.equals("")) {
            return "Untitled";
        } else {
            return text;
        }

    }

    public void setWorkArea(WorkArea work) {
        obj = work;
    }

    public WorkArea getWorkArea() {
        return obj;
    }

    public Toolbox getToolbox() {
        return toolbox;
    }

    public String getImageTitle() {
        return ImageTitle;
    }
}
